/*
 * @Author: szx
 * @Date: 2022-07-20 14:51:42
 * @LastEditTime: 2022-07-20 15:13:51
 * @Description:
 * @FilePath: \leetcode\500-599\565\565.js
 */
/**
 * @param {number[]} nums
 * @return {number}
 */
var arrayNesting = function (nums) {
    let res = 0;
    const n = nums.length,
        arr = new Array(n).fill(false);
    for (let i = 0; i < n; i++) {
        let cnt = 0;
        while (!arr[i]) {
            arr[i] = true;
            i = nums[i];
            cnt++;
        }
        res = Math.max(cnt, res);
    }
    return res;
};
